<template>
  <div>
    <div class="evaluate-shop">
      <div class="evaluate-shop-left">
        <div class="evaluate-shop-img" v-if="shop.smImageUrl" :style="'backgroundImage: url('+(shop.smImageUrl.substr(0,4).toLowerCase() == 'http' ? shop.smImageUrl : resUrl+shop.smImageUrl)+')'"></div>
        <div class="evaluate-shop-title">
          <h3>{{shop.name}}</h3>
          <span style="    background-color: rgb(197, 0, 0);
    color: rgb(255, 255, 255);
    font-size: 10px;
    height: 13px;
    line-height: 13px;
    padding: 0 5px;"
          >店铺认证</span>
        </div>
      </div>
      <div class="evaluate-shop-right">{{shop.creditRating}}</div>
    </div>

    <div class="evaluate-main">
      <div class="evaluate-star">
        <i class="icon icon-star" v-for="(v,k) in starArr" :key="k" :class="{active:k<score}" @click="clickStar(k)"></i>
      </div>
      <div class="evaluate-explain" v-if="score==0">请为店铺评分</div>
      <div class="evaluate-explain" v-else>{{evaluate.name}}</div>
      <!--<div class="evaluate-explain text-red" v-else-if="score==1">不满意各方面都很差</div>-->
      <!--<div class="evaluate-explain text-red" v-else-if="score==2">不满意，比较差</div>-->
      <!--<div class="evaluate-explain text-red" v-else-if="score==3">一般还需改善</div>-->
      <!--<div class="evaluate-explain text-red" v-else-if="score==4">比较满意，仍可改善</div>-->
      <!--<div class="evaluate-explain text-red" v-else>非常满意，无可挑剔</div>-->
      <div class="evaluate-content">
        <textarea class="weui-textarea" placeholder="请输入文本" rows="6" v-model="content"></textarea>
        <div class="weui-textarea-counter">非必填，至少输入8个字, <span>{{content.length}}</span>/100个字</div>
      </div>
    </div>

    <div class="btn-box">
      <button class="weui-btn weui-btn_warn" type="button" @click="subEvaluate">匿名提交</button>
    </div>

  </div>
</template>

<script>
  import {ipconfig} from '../../../../assets/js/ipconfig';
  import {getUser,getStatusMapByKey,getStatusByKeyVal} from '../../../../assets/js/tools';
  import {getShopDetail,evaluate} from '../../../../assets/js/getData';
  export default {
    name: "evaluate",
    data(){
      return {
        resUrl:ipconfig.resUrl,//图片、视频、音频等资源访问路径
        starArr:new Array(5),
        score:0,//当前评分
        evaluate:{},//当前评分对象
        shopId:null,
        orderId:null,
        userId:null,
        content:'',//评论内容
        shop:{},
      }
    },
    created(){
      this.shopId = this.$route.query.shopId;
      this.orderId = this.$route.query.orderId;
      this.userId = getUser().id;

      getShopDetail({id:this.shopId}).then(res => {
        if(res.data.reqResult.code>0){
          this.shop = res.data.data;
          console.log(this.shop);
        }else {
          Toast(res.data.reqResult.msg);
        }
      })
    },
    methods:{
      clickStar(k){
        this.score = k+1;
        this.evaluate = getStatusByKeyVal('eEvaluateType',this.score);
      },
      //提交评价
      subEvaluate(){
        if(this.score<=0){
          Toast('请选择评分');
          return
        }
        if(this.content.length>0&&this.content.length<8){
          Toast('至少输入8个字');
          return;
        }
        if(this.content.length>100){
          Toast('最多输入100个字');
          return;
        }
        let params = {
          shopId:this.shopId,
          orderId:this.orderId,
          userId:this.userId,
          level:this.score,
          content:this.content,
        };
        evaluate(params).then(res => {
          if(res.data.reqResult.code>0){
            Toast('评价成功');
            this.$router.replace({name:'myOrder'});
          }else {
            Toast(res.data.reqResult.msg);
          }
        })
      }
    }
  }
</script>

<style scoped>
  .evaluate-shop{
    display: flex;
    justify-content: space-between;
    height: 5.05rem;
    padding-left: 0.9rem;
    padding-right: 1.7rem;
    align-items: center;
    border-bottom: 1px solid #EEEEEE;
  }
  .evaluate-shop-left{
    display: flex;
    align-items: center;
  }
  .evaluate-shop-img{
    width: 1.55rem;
    height: 1.55rem;
    border-radius: 50%;
    margin-right: 0.55rem;
    background-origin: content-box;
    background-position:50% 50%;
    background-size:contain;
    background-repeat:no-repeat;
    background-color: rgba(0,0,0,0.2);
  }
  .evaluate-shop-img img{
    width: 100%;
  }
  .evaluate-shop-title{
    display: flex;
    align-items: center;
  }
  .evaluate-shop-title h3{
    color: #282828;
    font-size: 0.75rem;
    line-height: 0.75rem;
    margin-right: 0.2rem;
  }
  .evaluate-shop-right{
    padding-left: 1rem;
    background-image: url("../../../../../static/images/order/star.png");
    background-repeat: no-repeat;
    background-size: 0.7rem 0.65rem;
    background-position: left center;
  }
  .evaluate-main{
    padding: 1rem 1.7rem 0 1.7rem;
  }
  .evaluate-star{
    display: flex;
    justify-content: space-around;
  }
  .icon-star {
    font-size: 1.4rem;
    color: #CCCCCC;
  }
  .icon-star.active{
    color: #F9B523;
  }
  .evaluate-explain{
    color: #666666;
    font-size: 0.75rem;
    text-align: center;
    margin:1.25rem 0;
  }
  .text-red{
    color: #C50000;
  }
  .evaluate-content{
    background-color: #EEEEEE;
    padding: 0.4rem;
  }
  .evaluate-content .weui-textarea{
    background-color: #EEEEEE;
    color: #666666;
    font-size: 0.65rem;
    line-height: 0.85rem;
  }
  .weui-textarea-counter{
    color: #999999;
    font-size: 0.5rem;
  }
  textarea::-webkit-input-placeholder {
    color: #666666;
    font-size: 0.65rem;
  }
  textarea:-moz-placeholder {
    color: #666666;
    font-size: 0.65rem;
  }
  textarea::-moz-placeholder {
    color: #666666;
    font-size: 0.65rem;
  }
  textarea:-ms-input-placeholder {
    color: #666666;
    font-size: 0.65rem;
  }
  .btn-box{
    padding: 0 2.2rem;
    position: absolute;
    bottom: 1.35rem;
    left: 0;
    right: 0;
  }














</style>
